<template>
  <div class="erpLog">
    <div class="publicSearch">
<!--      <div class="searchBar" :style="{ height: isMoreSearch ? 'auto' : '' }">-->
<!--        <el-button-group>-->
<!--          <el-button @click="getBuyBillInData" size="mini" icon="el-icon-search"-->
<!--          >查询</el-button-->
<!--          >-->
<!--          <el-button @click="clearSearchData" size="mini" icon="el-icon-refresh"-->
<!--          >重置</el-button-->
<!--          >-->
<!--        </el-button-group>-->
<!--        <div>-->
<!--          <span>采购单号</span>-->
<!--          <el-input-->
<!--              v-model="searchData.billNo"-->
<!--              size="mini"-->
<!--              placeholder="采购单号"-->
<!--              clearable-->
<!--          ></el-input>-->
<!--        </div>-->
<!--        <div>-->
<!--          <span>审核状态</span>-->
<!--          <el-select-->
<!--              v-model="searchData.state"-->
<!--              size="mini"-->
<!--              filterable-->
<!--              placeholder="请选择审核状态"-->
<!--              clearable-->
<!--          >-->
<!--            <el-option-->
<!--                v-for="(item, index) in reviewStates"-->
<!--                :key="index"-->
<!--                :label="item.label"-->
<!--                :value="item.value"-->
<!--            >-->
<!--            </el-option>-->
<!--          </el-select>-->
<!--        </div>-->
<!--        <div>-->
<!--          <span>货主</span>-->
<!--          <el-select-->
<!--              v-model="searchData.organizationId"-->
<!--              size="mini"-->
<!--              filterable-->
<!--              placeholder="请选择货主"-->
<!--              clearable-->
<!--          >-->
<!--            <el-option-->
<!--                v-for="(item, index) in organizations"-->
<!--                :key="index"-->
<!--                :label="item.organizationName"-->
<!--                :value="item.organizationId"-->
<!--            >-->
<!--            </el-option>-->
<!--          </el-select>-->
<!--        </div>-->
<!--        <div>-->
<!--          <span>供应商</span>-->
<!--          <el-select-->
<!--              v-model="searchData.supplierId"-->
<!--              size="mini"-->
<!--              filterable-->
<!--              placeholder="请选择供应商"-->
<!--              clearable-->
<!--          >-->
<!--            <el-option-->
<!--                v-for="(item, index) in suppliers"-->
<!--                :key="index"-->
<!--                :label="item.supplierName"-->
<!--                :value="item.supplierId"-->
<!--            >-->
<!--            </el-option>-->
<!--          </el-select>-->
<!--        </div>-->
<!--        <div>-->
<!--          <span>采购类型</span>-->
<!--          <el-select-->
<!--              v-model="searchData.buyType"-->
<!--              size="mini"-->
<!--              filterable-->
<!--              placeholder="请选择采购单类型"-->
<!--              clearable-->
<!--          >-->
<!--            <el-option-->
<!--                v-for="(item, index) in buyBillInTypes"-->
<!--                :key="index"-->
<!--                :label="item.dictValue"-->
<!--                :value="item.dataDictDetailId"-->
<!--            >-->
<!--            </el-option>-->
<!--          </el-select>-->
<!--        </div>-->
<!--        <div>-->
<!--          <span>创建时间</span>-->
<!--          <el-date-picker-->
<!--              v-model="searchData.createTimeArr"-->
<!--              size="mini"-->
<!--              type="daterange"-->
<!--              value-format="yyyy-MM-dd"-->
<!--              range-separator="至"-->
<!--              start-placeholder="开始日期"-->
<!--              end-placeholder="结束日期"-->
<!--          >-->
<!--          </el-date-picker>-->
<!--        </div>-->
<!--        <div>-->
<!--          <span>预计到货时间</span>-->
<!--          <el-date-picker-->
<!--              v-model="searchData.expectTimeArr"-->
<!--              size="mini"-->
<!--              type="daterange"-->
<!--              value-format="yyyy-MM-dd"-->
<!--              range-separator="至"-->
<!--              start-placeholder="开始日期"-->
<!--              end-placeholder="结束日期"-->
<!--          >-->
<!--          </el-date-picker>-->
<!--        </div>-->
<!--        <div>-->
<!--          <span>关键字搜索</span>-->
<!--          <el-input-->
<!--              v-model="searchData.keyWords"-->
<!--              size="mini"-->
<!--              placeholder="自定义字段/创建者/备注"-->
<!--              clearable-->
<!--          ></el-input>-->
<!--        </div>-->
<!--      </div>-->

    </div>
    <div class="tableBox">
      <el-table
          highlight-current-row
          :data="tableData"
          @selection-change="handleSelectionChange"
          style="width: 100%"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="billNo" label="单号" align="center" header-align="center" />
        <el-table-column prop="dictValue" label="类型" align="center" header-align="center" />
        <el-table-column prop="billTypeId" label="单据类型id" align="center" header-align="center" />
        <el-table-column prop="code" label="状态" align="center" header-align="center" />
        <el-table-column prop="msg" label="备注" align="center" header-align="center" />
        <el-table-column label="操作" align="center" header-align="center">
          <template slot-scope="scope">
            <el-button
                type="primary"
                size="mini"
                @click="showDialog(scope.row.id)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          class="pagination-bottom"
          style="text-align: right"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          :current-page.sync="searchData.pageNum"
          :page-sizes="[15, 30, 50, 100]"
          :page-size="searchData.pageSize"
          layout="sizes,total, prev, pager, next"
          :total="searchData.total"
      >
      </el-pagination>


      <!--详情-->
      <el-dialog title="详情" :visible.sync="detailDialog">
        <el-table :data="detailData">
          <el-table-column property="sourceBillId" label="源单id" width="150"></el-table-column>
          <el-table-column property="sourceBillDetailRowIndex" label="行号" width="200"></el-table-column>
          <el-table-column property="batchNo" label="批号"></el-table-column>
          <el-table-column property="qty" label="数量">
            <template slot-scope="scope">
              <el-input v-model="scope.row.qty" ></el-input>
            </template>
          </el-table-column>

          <el-table-column property="areaName" label="仓库名称"></el-table-column>
          <el-table-column property="itemName" label="物料名称"></el-table-column>
          <el-table-column property="itemCode" label="物料编码"></el-table-column>
          <el-table-column property="close" label="是否关闭">
              <template slot-scope="scope">
                <el-switch
                    v-model="scope.row.close"
                    active-color="#13ce66"
                    inactive-color="#ff4949">
                </el-switch>
              </template>
          </el-table-column>
        </el-table>
        <div slot="footer" class="dialog-footer">
          <el-button @click="detailDialog = false">取 消</el-button>
          <el-button type="primary" @click="updateErpLog">确 定</el-button>
        </div>
      </el-dialog>


    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "erpLog",
  data() {
    return {
      detailDialog: false,
      detailData: [],
      parentId: '',
      searchData: {
        pageNum: 1,
        pageSize: 10,
        total: null,
        keyWords: "",
        wareId: PF.getLocal("wareId", "number"),
        organizationId: null,
        cellUseType: 3,
        itemName: "",
        itemCode: "",
      },
      tableData: []
    };
  },
  computed: {
    ...mapState(["reviewStates", "asnStates"]),
  },
  methods: {

    updateErpLog() {
      IOT.getServerData(
          "/transfer/updateErpLog/" + this.parentId,
          "post",
          this.detailData,
          (ret) => {
            if (ret.code === 200) {
              this.detailDialog = false;
            } else {
              IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
            }
          });
    },


    handleSizeChange(val) {
      this.searchData.pageSize = val;
      this.getBuyBillInData();
    },
    handleCurrentChange(val) {
      this.searchData.pageNum = val;
      this.getBuyBillInData();
    },
    clearSearchData() {
    },
    showDialog(val) {
      this.parentId = val;
      IOT.getServerData(
          "/erp/push/log/detail/" + val,
          "get",
          null,
          (ret) => {
            if (ret.code === 200) {
              this.detailDialog = true;
              this.detailData = ret.rows;
              this.searchData.total = ret.total;
              this.searchData.pageNum = ret.pageNumber;
            } else {
              IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
            }
          },false);
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    getBuyBillInData() {
      IOT.getServerData(
          "/erp/push/log/page",
          "get",
          this.searchData,
          (ret) => {
            if (ret.code === 200) {
              this.tableData = ret.rows;
              this.searchData.total = ret.total;
              this.searchData.pageNum = ret.pageNumber;
            } else {
              IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
            }
          }
      );
    }
  },

  activated() {
    this.getBuyBillInData();
  },

};
</script>

<style scoped lang="less">
.buyBillIn {
}
</style>
